package org.spindle.soasuite.datasource.internal.core;

import org.hibernate.Query;
import org.spindle.soasuite.data.internal.User;
import org.spindle.soasuite.datasource.internal.api.IUserDAO;

class UserDAO extends ADatasourceDAO implements IUserDAO {

    @Override
    public User getUser(String username, String password) {
        User user = null;

        Query q = prepareQuery("select u from user as u where u.username=:username and u.password=:password");
        q.setString("username", username);
        q.setString("password", password);
        user = (User) q.uniqueResult();

        return user;
    }

    @Override
    public User getUser(int userId) {
        User user = null;

        Query q = prepareQuery("select u from user as u where u.id=:userId");
        q.setInteger("userId", userId);
        user = (User) q.uniqueResult();

        return user;
    }
}
